function searchSogou(input_id) {
	var sgi = $(input_id),
	url = 'http://www.sogou.com/web?ie=utf8&query=',
	isa = sgi.getAttribute('isActive'),
	v = isa && isa == 'true' ? sgi.value : '',
	par = encodeURIComponent(v);
	window.open(url + par);
	if(isa) sgi.value = '';
}

function searchMail() {
	mailSearch.startSearch('search_mail_content');
}

function isOpenSearch() {
	openSearchModule ? (function() {
		$('search_mail_input').show();
		$('search_input').hide();
	})() : (function() {
		$('search_input').show();
		$('search_mail_input').hide();
	})();
}

// 动态载入passport JS文件，并且判断载入完毕后执行绘制卡片和组的函数
function JSLoadPP() {
	PassportSC.logoutHandle = function(ele, lfc, lsc) {
		if (typeof(ele) != "object") {
			return false;
		}
		// var logout_status = "";
		if (this.domain == "") {
			this.domain = this.getDomain();
		}
		var ra = this.getTime();
		var url = 'http://passport.sohu.com/sso/logout.jsp?s=' + ra + '&appid=' + this.appid;
		if (this.domain != "sohu.com") {
			url += "&domain=" + this.domain;
		}
		var self = this;
		loadScript(url, function() {
			self.logoutIntervalProc(lfc, lsc, ele);
		});
	};
	
	PassportSC.logoutIntervalProc = function(lfc, lsc, ele) {
		if (this.logoutRedirectUrl == "") {
			this.autoProcAllDomain("logout", ele);
		} else {
			this.addCookie("crossdomain_logout", this.getTime(), 336);
		}
		// window.location.href = 'http://vip.' + localDomain;
		var rdurl = USE_SYS.name == 'vip.sohu' ? USE_SYS.protocol + '//vip.' : USE_SYS.protocol + '//mail.'
		window.top.location.href = rdurl + localDomain;
	};  
	try {
		PassportSC.cookieHandle();
		if(USE_SYS.name != 'vip.sohu') loadPassportGroup();
	} catch(e) {}
	try {
		RECORD_LOAD_TIME.push(+new Date());
	} catch(e) {}
}

function setUserInfo() {
	var _first_list = null;
	var _setInfo = function(){
		var _new_list = [].concat(_first_list).slice(0, 20);
		var new_contact_unread_item, contact_unread_item, contact_item, unread_item_flag = false, item_flag = false,
		have_read = function(item) {
			return isConferenceMode ? item.unread == 0 : item.have_read;
		},
		mid = function(item) {
			return isConferenceMode ? item.thread : item.rowid;
		},
		strflag = (function() {
			return isConferenceMode ? '会话' : '邮件';
		})(),
		index = 0, flag_one = false, flag_two = false, flag_three = false, sender_obj = {},
		_nnt = $('ID_NEWNOTICE'), _flag = false;
		if(!_nnt) {return false;}
		for(var i=0,len=_new_list.length;i<len;i++) {
			var item_env = _new_list[i].envelope, 
			_f = item_env.from.concat(item_env.from_after_1st_unread),
			_in_c = false, _sender = {};
			_f.each(function(item) {
				var _n = mailAddressClass.addressHash.contact.email[item[1]];
				if (mailAddressClass.addressHash.contact.email[item[1]]) {
					_sender = {nick: _n, email: item[1]};
					_in_c = true;
				}
			});
			if(i == 0 && !have_read(_new_list[i]) && _in_c && !flag_one) {
				new_contact_unread_item = _new_list[i];
				sender_obj = _sender;
				flag_one = true;
			} else if(!have_read(_new_list[i]) && _in_c && !flag_two) {
				contact_unread_item = _new_list[i];
				sender_obj = _sender;
				flag_two = true;
			} else if(_in_c && !flag_three) {
				contact_item = _new_list[i];
				sender_obj = _sender;
				flag_three = true;
			}
		}
		if(new_contact_unread_item) {
			var _sb = new_contact_unread_item.envelope.subject;
			_sb = !_sb || _sb == '' ? '无标题' : _sb;
			_nnt.innerHTML = '[新'+ strflag +'] <a href="javascript:;" class="s_read_mail" mid="'+ mid(new_contact_unread_item) +'"><b>' + _sb + '</b></a>&nbsp;&nbsp;<span title="'+ _sender.email +'">发件人：<b>'+ sender_obj.nick +'</b></span>';
		} else if(contact_unread_item) {
			_nnt.innerHTML = '<b>' + sender_obj.nick + '</b> 给你发了一封邮件，快给他<a href="javascript:;" class="s_reply_mail" mid="'+ mid(contact_unread_item) +'">回复</a>吧！';
		} else {
			_nnt.innerHTML = '关系需要常联系，给朋友发去<a href="javascript:;" class="s_compose_mail">问候</a>吧！';
			// 圣诞活动
			// _nnt.innerHTML = '<a target="_blank" href="http://goto.mail.sohu.com/goto.php?code=welc_09xmas" style="color:#ff6600;">箱亲们，圣诞节来了，送贺卡啦！</a>';
		}
		var _uc = $('ID_UNREADCOUNT'), _uf = $('ID_UNREADFOLDER'), ff = isConferenceMode ? mailConference.F.folders : FolderList, _f = [], _u1 = 0, _u2 = 0;
		try {
			if(ff && ff.length > 0) {
				_f = ff;
			} else {
				_f = FOLDER.evalJSON().folder;
			}
			_f.each(function(item) {
				if (item.folder_id == -2) {
					_u1 = item.unread;
					_u2 = item.thread_unread;
				}
			});
		} catch(e) {}
		if(isConferenceMode) {
			_uc.innerHTML = _u2;
		} else {
			_uc.innerHTML = _u1;
		}
		_uf.innerHTML = '未读' + strflag;
	}

	
	var loopTimes = 5;
	var _getMail = function(){		
		if(--loopTimes<0)
			return false;
		_first_list = isConferenceMode ? mailConference.getListCache(1, 1) : mailList.mailListCache['inbox1'][0];
		if (!_first_list || _first_list.length == 0) {
			setTimeout(arguments.callee, 500);
			return false;
		}
		else{
			_setInfo();
		}
	}
	_getMail();
}

//
function setSpaceSize(){
    var totalsize = FoldersData.totalSize;
	var is_use = (totalsize >= mailContentTotalSize)?"100%":Math.round((totalsize/mailContentTotalSize)*1000)/10 + "%"; 
    var html = '<div style="padding-left:20px"><div class="am update-capacity s_mobile_mail" style="float:none;"></div></div>'
			+'<div class="am schedule" style="float:none;">'
            +'<span class="amv" id="used_percent" style="width:'+is_use+'"></span>'
            +'</div>'
            +'<div style="float:left;padding:3px 0 0">'
            +'可用空间容量：<span id="total_size">'+strfsize(parseInt(mailContentTotalSize)-parseInt(totalsize))+'</span>'
			+'</div>';
    if(G.isMobileUser()){
        html = '<div><img align="absmiddle" src="'+MailConst.ALL+'/icon_wuxian.jpg"/>'
            +'已用容量 <span id="total_size">'+ strfsize(totalsize) +'</span>';
    }
    $('ID_SPACESIZE').innerHTML = html;
}
// 邮箱首页个人信息，
function showUserInfo() {
	var expire_time = new Date(parseInt(G.userinfo.user_expire_date));
	expire_time = ""+expire_time.getFullYear()+"-"+(expire_time.getMonth()+1)+"-"+expire_time.getDate();
	var s = '<div class="mail">'+
		    //'<h3>您好，'+(PROFILE.fullname?PROFILE.fullname:SUID)+'</h3>'+
            // '<div class="level"><span class="am icon1"></span><span>积分：<a hidefocus="true" href="http://score.mail.sohu.com/product.action" target="_blank" title="上积分兑奖品" onclick="jsoplog.ucCapture(\'mailScoreIndex\')"><b id="mail_score">12</b></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;等级：</span><span id="mail_score_img"><span class="am score-silver" title="可用积分：12"></span></span><span id="scoremail" style="margin-top: -25px;position:absolute;"></span></div>'+
            '<div><span class="am icon2"></span><a hidefocus="true" id="ID_UNREADCOUNT" style="font-weight:900;margin: 0 5px 0 0;cursor:pointer;">0</a>封<a hidefocus="true" id="ID_UNREADFOLDER" style="cursor:pointer;">未读邮件</a>！</div>'
			+'<div class="prompt">'
			+'<span class="am icon_score icon3"></span>'
			+'<span id="ID_NEWNOTICE">关系需要常联系，给朋友发去<a href="javascript:;" class="s_compose_mail">问候</a>吧！</span>'
			+'</div>'
			+'<div style="clear:both;float:left">'
			+'<li>目前邮箱状态：'+G.mailStatus+'</li>'
            +'<li>到期时间：'+expire_time+'&nbsp;&nbsp;&nbsp;&nbsp;'
            +'<input type="button" value="我要续费"  onclick="payForMail();return false;"/>'
			+'</li>'
			+'</div>'
			+'<div class="spaces" id="ID_SPACESIZE" style="float:right;clear:none;width:160px"></div>'
			+'</div>';



	$('info').innerHTML = s;
	setSpaceSize();
	setUserInfo();
}

// 欢迎页内容展现
function showMainMail() {
	var _mp = DOM.mainPage ? DOM.mainPage : $('mainPage');
	_mp.innerHTML = vipMainTemplate;
}

// vip的天气预报模块
function showWeather() {
	weather_get({domain:localDomain}, function(ret) {
		var today = ret.today, tomorrow = ret.tomorrow, t = new Template(weatherTemplate), data={};
		data['time'] = newtime();
		data['city'] = today['city'];
		data['todayphoto'] = today['photo'].replace("http://news.sohu.com","/static/weather");
		data['todayweather'] = today['weather'];
		data['todaylow'] = today['low'];
		data['todayhigh'] = today['high'];
		data['tomorrowphoto'] = tomorrow['photo'].replace("http://news.sohu.com","/static/weather");
		data['tomorrowweather'] = tomorrow['weather'];
		data['tomorrowlow'] = tomorrow['low'];
		data['tomorrowhigh'] = tomorrow['high'];
		try {
			$('weather').innerHTML = t.evaluate(data);
		} catch(e) {}
	});
}

// 实时大盘指数的显示
function showStockModule() {
	var d = $('stock_module');
	if(!d) return;
	if(PROFILE.feedstock!=0 && !G.isTryoutFrozen){
        //设置股票
        var s=MailConst.IMG.split("/");
        var i=s.length;
        var color=(s[i-2]=="green"?"#EFF4F3":(s[i-2]=="blue")?"#ecf1f7":"#f4f3f1");
		color="#FFF";
        var stockUrl = G.urlProtocol=="https"?"/static/stock1/cp/mail/mail_index.shtml":"http://q.stock.sohu.com/cp/mail/mail_index.shtml";
		d.style.display = '';
        d.innerHTML = '<div style="text-align:center"><strong onclick="changePanel(\'stockChannel\');" style="cursor:pointer">股票时时通</strong></div>'    
            +'<iframe id="_IFR_STOCK" name="_IFR_STOCK" src="'+stockUrl+'?color='+color+'"'
            +' height="168px" width="168px" marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0" scrolling="no"></iframe>';
    }
	else{
		d.style.display='none';
	}
	/*
	d.innerHTML = '<div><b>股票时时通</b></div>'
				 +'<div><iframe style="width:168px;height:168px;border:0;" frameborder="0" scrolling="0" src="/static/stock1/cp/mail/mail_index.shtml"></iframe></div>'
	*/
}

function newtime(){	
	var now = new  Date(), yyy = now.getYear();
    if(yyy < 2007){
       yyy += 1900;
    }
    var mmm = now.getMonth(), ddd = now.getDate(), day = now.getDay(),
    weeks = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
    //2007年3月19日 星期三
    return yyy + '年' + (mmm+1) + '月' + ddd + '日' + ' ' + weeks[day];	
}

// 发信成功页面内容
function showSendSucc() {
	$('sendSuc').update(sendMailSuccTemplate);
}

// 邮箱系统的首页展示
function loadMailMainPage() {
	// 载入首页的html
	try {
		showMainMail();
	} catch(e) {}
	// 载入用户在邮箱中的相关信息
	try {
		showUserInfo();
	} catch (e) {}
	try {
		showWeather();
	} catch(e) {}
	try {
		showStockModule();
	} catch(e) {}
	// 载入推荐信息
	try {
		setRecommend();
	} catch(e) {}
}

function firstLoad() {
	loadMailMainPage();
}

/*******************************************************************/
// 写信页面内容
function showComposeMail() {
	DOM.composeMail.innerHTML = writeMailTemplate;
	// 初始化写信页面中用到的DOM元素
	DOM.mail_operate_message = $('mail.operate.message');
	DOM.upload_iframe_content = $('upload_iframe_content');
	DOM.compose_subject = $('compose.subject');
	DOM.compose_wto = $('compose.wto');
	DOM.compose_wcc = $('compose.wcc');
	DOM.compose_wbcc = $('compose.wbcc');
	DOM.securityCode = $('securityCode');
	// DOM.checkSign = $('checkSign');
	DOM.uploadInfoDIV = $('uploadInfoDIV');
	DOM.editor_mess2 = $('editor.mess2');
	// DOM.compose_editer = $('compose.editer');
	DOM.compose_mess1 = $('compose.mess1');
	DOM.compose_mess2 = $('compose.mess2');
	// DOM.user_sign_area = $('user_sign_area');
	DOM.mail_cc = $('mail.cc');
	DOM.mail_bcc = $('mail.bcc');
	DOM.writemail_area = $('writemail_area');
	DOM.saveCheckbox1 = $('saveCheckbox1');
	DOM.saveCheckbox2 = $('saveCheckbox2');
}


// 头部区域的事件代理
function tpEventDelegation() {
	var _tmp_dl = [
		{name: 's_mainpage', event: function(event) {
			jsoplog.ucCapture( 'mailindex' );
			changePanel('mainPage');
		}},
		{name: 's_logout', event: function(event) {
			jsoplog.ucCapture( 'mailexit' );
			doLogout();
		}},
		{name: 's_config', event: function(event) {
			jsoplog.ucCapture( 'mailconfig' );
			changePanel('mailConfiguration', 'initMailCfg');
		}},
		{name: 's_overview_c', event: function(event, EL) {
			MLMD('conference');
			EL = $(EL);
			try {
				EL.removeClassName('s_overview_c');
				EL.innerHTML = '返回普通模式';
			} catch(e) {}
			try {
				var _tc = setTimeout(function() {
					clearTimeout(_tc);
					_tc = null;
					EL.addClassName('s_con_c');
				}, 500);
			} catch(e) {}
			try {
				jsoplog.ucCapture('useconference');
			} catch(e) {}
		}},
		{name: 's_con_c', event: function(event, EL) {
			MLMD('mail');
			EL = $(EL);
			try {
				EL.removeClassName('s_con_c');
				EL.innerHTML = '体验会话模式';
			} catch(e) {}
			try {
				var _tc = setTimeout(function() {
					clearTimeout(_tc);
					_tc = null;
					EL.addClassName('s_overview_c');
				}, 500);
			} catch(e) {}
			try {
				jsoplog.ucCapture('usecommon');
			} catch(e) {}
		}},
		{name: 's_search_web', event: function(event, EL) {
			searchSogou('search_web_content');
			// searchMail();
		}},
		{name: 's_search_mail', event: function(event, EL) {
			searchMail();
		}},
		{name: 's_search_other', event: function(event, EL) {
			var e = EL.previousSibling;
			var mlist = [{
            	text: '搜索网页',
            	onclick: function(){
					searchSogou('search_mail_content');
                	return false;
            	}
        	}];
			menu.showMenu(EL.parentNode, DOM.sohuMailMain, mlist, 'menu menu-search', true, null, event);
		}}
	];
	Event.observe(DOM.navbg, 'click', function(event) {
		var EL = $(event.target);
		_tmp_dl.each(function(item) {
			if(Element.hasClassName(EL, item.name)) {
				eventStop(event);
				item.event(event, EL);
				return false;
			}
		});
	});
	Event.observe(DOM.navbg, 'mousedown', function(event) {
		var EL = $(event.target), tmp_md_dl = ['s_overview_c', 's_con_c'];
		tmp_md_dl.each(function(item) {
			if(Element.hasClassName(EL, item)) {
				try {
					Element.addClassName(EL, 'use-con-press');
				} catch(e) {}
				eventStop(event);
			}
		});
		return false;
	});
	Event.observe(DOM.navbg, 'mouseup', function(event) {
		var EL = $(event.target), tmp_md_dl = ['s_overview_c', 's_con_c'];
		tmp_md_dl.each(function(item) {
			if(Element.hasClassName(EL, item)) {
				try {
					Element.removeClassName(EL, 'use-con-press');
				} catch(e) {}
				eventStop(event);
			}
		});
		return false;
	});
	Event.observe($('search_web_content'), 'keypress', function(event) {
		if(event.keyCode == 13) {
			searchSogou('search_web_content');
		}
	});
	var _smc = $('search_mail_content');
	Event.observe(_smc, 'keydown', function(event) {
		if(event.keyCode == 13) {
			searchMail();
		}
	});
	Event.observe(_smc, 'focus', function(event) {
		var _isa = _smc.getAttribute('isActive');
		if(_isa && _isa == 'true') return false;
		Element.removeClassName(_smc, 'input-grey');
		_smc.value = '';
		_smc.setAttribute('isActive', 'true');
	});
	var _swb = $('search_mail_input').getElementsByClassName('s_search_other')[0];
}

// 左侧列表的事件代理
function lfEventDelegation() {
	var _tmp_dl = [
		{name: 's_checkmail', event: function(event) {
			checkNewMail(true);
			jsoplog.ucCapture('mailcheck');
            jsoplog.sendPV('checkmail');
		}},
		{name: 's_writemail', event: function(event) {
			changePanel('composeMail');
			receiverNumPrompt();
			jsoplog.ucCapture('mailwrite');
            jsoplog.sendPV('composemail');
		}},
		{name: 's_address', event: function(event) {
			changePanel('contactList');
			jsoplog.ucCapture('mailaddress');
            jsoplog.sendPV('contact');
		}},
		{name: 's_unread', event: function(event) {
			changePanel('mailList', -2);
			jsoplog.ucCapture('mailunread');
            jsoplog.sendPV('unread');
		}},
		{name: 's_inbox', event: function(event) {
			changePanel('mailList', 1);
			jsoplog.ucCapture('mailinbox');
            jsoplog.sendPV('inbox');
		}},
		{name: 's_draft', event: function(event) {
			changePanel('mailList', 2);
			jsoplog.ucCapture('maildraft');
            jsoplog.sendPV('draft');
		}},
		{name: 's_send', event: function(event) {
			changePanel('mailList', 3);
			jsoplog.ucCapture('mailsent');
            jsoplog.sendPV('sent');
		}},
		{name: 's_delete', event: function(event) {
			changePanel('mailList', 4);
			jsoplog.ucCapture('maildelete');
            jsoplog.sendPV('trash');
		}},
		{name: 's_junk', event: function(event) {
			changePanel('mailList', 5);
			jsoplog.ucCapture('mailgabage');
            jsoplog.sendPV('junk');
		}},
		{name: 's_myfolder_', event: function(event) {
			if(arguments[1]) {
				var _el = arguments[1], _cn = 's_myfolder_', _fid,
				// var _id = _el.className.include(_cn) ? _el.className : _el.parentNode.className.include(_cn) ? _el.parentNode.className : _el.parentNode.parentNode.className.include(_cn) ? _el.parentNode.parentNode.className : _el.parentNode.parentNode.parentNode.className.include(_cn) ? _el.parentNode.parentNode.parentNode.className : '';
				_id = _el.className.split(' ');
				_id.each(function(item) {
					if(item.include(_cn)) _fid = item;
				});
				_fid = _fid.split('_')[2];
				if (_fid && typeof (_fid*1) == 'number') {
					changePanel('mailList', _fid);
					jsoplog.ucCapture('mailfolder' + _fid);
            		jsoplog.sendPV('folder' + _fid);
				}
			}
		}},
		{name: 's_foldermanage', event: function(event) {
			changePanel('newFolderList');
			jsoplog.ucCapture('mailuserfolder');
		}},
		{name: 's_foldercreate', event: function(event) {
			changePanel('addFolderList');
			jsoplog.ucCapture('mailaddfolder');
		}},
		{name: 's_daishoumanage', event: function(event) {
			mailPop.getPop3List();
			jsoplog.ucCapture('daishoumanage');
		}},
		{name: 's_daishoucreate', event: function(event) {
			mailPop.setPop3Account();
			$('ID_IPT_POPUID').focus();
			jsoplog.ucCapture('daishoucreate');
		}},
		{name: 's_score', event: function(event) {
			changePanel('score');
			jsoplog.ucCapture( 'mailscore' );
		}},
		{name: 's_greetcard', event: function(event) {
			changePanel('card');
			jsoplog.ucCapture( 'mailcard' );
		}},
		{name: 's_mainpage', event: function(event) {
			changePanel('mainPage');
			jsoplog.ucCapture( 'mailindex' );
		}},
		{name: 's_config', event: function(event) {
			changePanel('mailConfiguration', 'initMailCfg');
			jsoplog.ucCapture( 'mailconfig' );
		}},
		{name: 's_show_box', event: function(event, EL) {
			var e = EL.parentNode.nextSibling;
			while(e.nodeType != 1){
				e = e.nextSibling;
			};
			e = $(e);
			var ce = $(EL.firstChild);
			if(!e.hasClassName('menu_box')) return false;
			if(e.visible()) {
				ce.removeClassName('box-arrow-up');
				ce.addClassName('box-arrow-down');
				e.hide();
			} else {
				ce.removeClassName('box-arrow-down');
				ce.addClassName('box-arrow-up');
				e.show();
			}
		}},
		{name: 's_mobile_mail', event: function(EL, event) {
			changePanel('mobileConfiguration');
			jsoplog.ucCapture('mailmobile');
		}},
		{name: 's_vip_special', event: function(EL, event) {
			changePanel('mailConfiguration', 'vipSpecialArea');
			jsoplog.ucCapture('vipspecial');
		}},
		{name: 's_vip_business', event: function(EL, event) {
			changePanel('mailConfiguration', 'vipBusinessArea');
			jsoplog.ucCapture('vipbusiness');
		}}
	];
	Event.observe(DOM.left, 'click', function(event) {
		var EL = event.target;
		_tmp_dl.each(function(item) {
			if(item.name == 's_myfolder_') {
				var e = Element.getParentNodeByClassName(EL, item.name, true);
			} else {
				var e = Element.getParentNodeByClassName(EL, item.name);
			}
			if(e) {
				eventStop(event);
				item.event(event, e);
				return false;
			}
		});
	});
	Event.observe(DOM.left, 'mouseover', function(event) {
		var EL = $(event.target);
		if(EL.hasClassName('s_renew')) {
			var _href = EL.href;
			if(!_href.include(UserSohuID)) {
				EL.href = _href + UserSohuID;
			}	
		}
	});
    //
    var nodes = $$(".s_udisk_entrance");
    nodes.each(function(item){
        item.onclick = function(event){
            jsoplog.ucCapture('udisk_click_left');
			if(frozenAlert())
				return false;
            //return showUdiskPanel.apply(this);
        }
    })
	
	$("momail_info_wuxian").onclick = function(){
		jsoplog.ucCapture( 'wuxian_vip_left' );
        window.open("http://ad.mail.sohu.com/mail/tg/091102vipwxl.html");
	}
}

// 首页面的事件代理
function mainEventDelegation() {
	var _pop_input_id = $('pop_input_id'), _dm = 'yourname@21cn.com';
	var _tmp_dl = [
		{name: 's_mobile_mail', event: function(EL, event) {
			changePanel('mobileConfiguration');
			jsoplog.ucCapture('mailmobile');
		}},
		{name: 's_daishoumanage', event: function(EL, event) {
			mailPop.getPop3List();
			jsoplog.ucCapture('daishoumanage');
		}},
		{name: 's_read_mail', event: function(EL, event) {
			var mid = EL.getAttribute('mid');
			try {
				if (isConferenceMode) {
					mailConference.folder = 1;
					mailConference.getMailRead(mid);
				} else {
					mailList.currentFolder = 1;
					mailRead._prev_page = null, mailRead._next_page = 1;
					mailRead.folder = 1;
					mailRead.page = 0;	
					mailRead.getMailRead(mid);
				}
			} catch(e) { }
		}}, {name: 's_reply_mail', event: function(EL, event) {
			var mid = EL.getAttribute('mid');
			try {
				if(isConferenceMode) {
					mailConference.folder = 1;
					mailConference.read_mail_callback_exec = function() {
						mailConference.replyMail(mailConference._last_id, 'replyall');
					};
					mailConference.getMailRead(mid);
				} else {
					mail_read({id: mid}, function(ret) {
						mailRead.currentMail = ret;
						mailRead.replyMail('reply');
					});
				}
			} catch(e) { }
		}}, {name: 's_compose_mail', event: function(EL, event) {
			changePanel('composeMail');
		}}, {name: 's_create_pop', event: function(EL, event) {
			mailPop.setPop3Account();
			var _p_id = $('ID_IPT_POPUID');
			_p_id.value = _pop_input_id.value != _dm ? _pop_input_id.value : '';
			_p_id.focus();
			jsoplog.ucCapture('daishoucreate');
		}}, {name: 's_vip_special', event: function(EL, event) {
			changePanel('mailConfiguration', 'vipSpecialArea');
		}}, {name: 's_vip_business', event: function(EL, event) {
			changePanel('mailConfiguration', 'vipBusinessArea');
		}}, {name: 's_translate_demo', event: function(EL, event) {
			changePanel('mailConfiguration', 'translateDemo');
		}}, {name: 's_map_demo', event: function() {
			changePanel('mailConfiguration', 'mapDemo');
		}}, {name: 's_pop_demo', event: function() {
			mailPop.getPop3List();
			var _b = document.createElement('b');
			_b.innerHTML = '[<a class="grey s_rt_business" href="javascript:;">返回商务通首页</a>]';
			DOM.mailConfiguration.getElementsByTagName('h4')[0].appendChild(_b);
		}}
	];
	Event.observe(DOM.mainPage, 'click', function(event) {
		var EL = $(event.target);
		_tmp_dl.each(function(item) {
			var e = Element.getParentNodeByClassName(EL, item.name);
			if(e) {
				item.event(e, event);
				if(!e.getAttribute('target')) Event.stop(event);
			}
		});
		return false;
	});
	Event.observe(DOM.mainPage, 'mouseover', function(event) {
		var EL = $(event.target),
		e = Element.getParentNodeByClassName(EL, 's_tab_switch');
		if(e) {
			$A(e.parentNode.childNodes).each(function(item) {
				Element.removeClassName(item, 'tab-focus');
			});
			Element.addClassName(e, 'tab-focus');
			var index = e.getAttribute('index');
			$A(e.parentNode.nextSibling.childNodes).each(function(item) {
				item.style.display = 'none';
			});
			e.parentNode.nextSibling.childNodes[index].style.display = '';
			Event.stop(event);
		}
		return false;
	});
	Event.observe(_pop_input_id, 'focus', function(event) {
		if(_pop_input_id.value.strip() == _dm) _pop_input_id.value = '';
	});
	Event.observe(_pop_input_id, 'blur', function(event) {
		if(_pop_input_id.value.blank()) _pop_input_id.value = _dm;
	});
}


// 发信成功页面显示
function sendSuccess() {
	DOM.sendSuc.show();
}

// 邮件首页显示
function mailMainPage() {
	hiddenAllPanel();
	changeToolbarStyle('');
	DOM.mainPage.show();
	try {
		setUserInfo();
	} catch(e) {}
	try {
		deleteLoadPage();
	} catch(e) {}
	showStockModule();
	try {
		addAjaxHistory('mailMain', 'changePanel("mainPage", null, true)', 'VIP邮箱', arguments[0]);
	} catch(e) {}
}

// 初始化页面panel的DOM节点
function initPanelDOM() {
	DOM.sohuMailMain = DOM.sohuMailMain ? DOM.sohuMailMain : $('sohuMailMain');
	DOM.mainPage = DOM.mainPage ? DOM.mainPage : $('mainPage');
	DOM.composeCardMail = DOM.composeCardMail ? DOM.composeCardMail : $('composeCardMail');
	DOM.composeMail = DOM.composeMail ? DOM.composeMail : $('composeMail');
	DOM.sendSuc = DOM.sendSuc ? DOM.sendSuc : $('sendSuc');
	DOM.mailList = DOM.mailList ? DOM.mailList : $('mailList');
	DOM.mailSearch = DOM.mailSearch ? DOM.mailSearch : $('mailSearch');
	DOM.newFolderList = DOM.newFolderList ? DOM.newFolderList : $('newFolderList');
	DOM.readMail = DOM.readMail ? DOM.readMail : $('readMail');
	DOM.addressGroupList = DOM.addressGroupList ? DOM.addressGroupList : $('addressGroupList');
	DOM.mailConfiguration = DOM.mailConfiguration ? DOM.mailConfiguration : $('mailConfiguration');
	DOM.mobileConfiguration = DOM.mobileConfiguration ? DOM.mobileConfiguration : $('mobileConfiguration');
	DOM.customMail = DOM.customMail ? DOM.customMail : $('customMail');
	DOM.left = DOM.left ? DOM.left : $('left');
	DOM.navbg = DOM.navbg ? DOM.navbg : $('navbg');
	// 用户自建文件夹区域
	DOM.newfolderArea = DOM.newfolderArea ? DOM.newfolderArea : $('newfolderArea');
}

// 加载PV js
function loadPVjs() {
	if(ExecFunc("G.urlProtocol=='https'")===true)
		return;
	//加载PV
	function m_s(){
		var c = escape((new Date().getTime()) * 1000 + Math.round(Math.random() * 1000));
		r = (typeof(encodeURI) == 'function') ? encodeURI(document.referrer) : document.referrer;
		if (document.cookie.indexOf("SUV=") < 0 || document.cookie.indexOf("IPLOC=") < 0) {
			var pv_script = document.createElement('script');
			pv_script.setAttribute('src', 'http://suvset.sohu.com/suv/" + c + "');
			document.body.appendChild(pv_script);
		}
		var _script = document.createElement('script');
		// img.setAttribute('id', 'pv_img_id');
        //pv加入宽高要求
        //alva - 2009/06/16
        var screen_w = window.screen.width;
        var screen_h = window.screen.height;
		_script.setAttribute('src', 'http://pv.sohu.com/pv.gif?t?='+c+ "_"+screen_w+"_"+screen_h+'?r?='+r);
		document.body.appendChild(_script);
	}
	var spv;if(!spv)m_s();spv=1;
}

/***************** vip邮箱中特有的一些功能函数 *****************/
//签名相关
function onEndCrop(coords, dimensions){
	position_sign[0]=coords.x1;
	position_sign[1]=coords.y1;
	position_sign[2]=dimensions.width;
	position_sign[3]=dimensions.height;
}
function docrop(){
	var params = {
		x : position_sign[0],
		y : position_sign[1],
		width : position_sign[2],
		height : position_sign[3],
		email : UID.split("@")[0],
		domain : 1,
		flag : 0,
		filename: img_filename
	};
    _defun('http://vip.sohu.com/sign/act/ImageHandle', 'post', params,__createImgCallBack);


}

function __createImgCallBack(ret){
	if (ret.is_success) {
		var imgname = ret.filename;
		image_signature_name=imgname;
		$('demoimg').src = SIGN_ROOT + '/' + imgname+'.jpg?' + Math.random();
		$('previewArea').src = imgname + '?' + Math.random();
		mailCfgClass.setMailCfgSignImg();
	}else{
		alert(ret.message);
	}
}
//vip 全部完成加载的时候执行
function completeLoad(){	
	ExecFunc(frozenAlert);
	ExecFunc("K.config.enabled=false");
	if($('ID_MAX_ATT_SIZE')){
		$('ID_MAX_ATT_SIZE').innerHTML = "( 可上传"+strfsize(G.maxAttachmentSize)+")";
	}
	setTimeout(initCiba,3000);
}
/*******************************/
var ID_SIGN = "cardSign";
function addCardSignInWriteMail(){	
        jsoplog.ucCapture('card');
		if (!CardSign.getProfileContent().signatureCard|| CardSign.getProfileContent().signatureCard.strip() == "{}") {
			alert("您的名片签名为空，请先设置签名！");
			return;
		}
		var currentSign = "";
		if (writemail.defaulteditor == "html") {
			try {
				if(!CardSign.getProfileContent().image_signature) {
					currentSign = "<div id='"+ID_SIGN+"'><br /><br /><div id='textCardSign'>"
					+decideSignature() + "</div></div>";
				} else {
					if (CardSign.getProfileContent().image_signature_name) {
						currentSign = "<div id='"+ID_SIGN+"'><br /><br /> <div id='imageSign' style='height:150px'><img src=" +SIGN_ROOT + "/"+ CardSign.getProfileContent().image_signature_name + ".jpg?"+Math.random()+"  style='width:148px;height:106px;margin: 0px 4px 8px 15px; float: left; display: inline;'/>"
						+"<div id='textCardSign' style='margin: 0px 28px 28px 0px; float: left;'>" +decideSignature()
						+"</div></div><div style='clear:both;'></div></div>";
					}else{
						currentSign = "<div id='"+ID_SIGN+"'><br /><br /> <div id='imageSign' style='height:150px'><img src='"+ MailConst.IMG+"/demo1.jpg'  style='width:148px;height:106px;margin: 0px 4px 8px 15px; float: left; display: inline;'/>" 
						+"<div id='textCardSign' style='margin: 0px 28px 28px 0px; float: left;'>"+decideSignature()+
						"</div></div><div style='clear:both;'></div></div>";
					}
				}
			} catch(e) {alert(e);}
		} else {
			currentSign = "\n\n\n\n\n \n "+ decideSignature();
		}
		if (Editor.c().document.getElementById(ID_SIGN)&& Editor.c().document.getElementById(ID_SIGN) != null) {
			try {
				if(!CardSign.getProfileContent().image_signature) {
					Editor.c().document.getElementById(ID_SIGN).innerHTML = "<br/><br/><div id='textCardSign'>" +
						decideSignature()+"</div>";
				} else {
					if (CardSign.getProfileContent().image_signature_name) {
							Editor.c().document.getElementById(ID_SIGN).innerHTML = "<br/><div id='imageSign' style='height:150px'>"
							+"<img src=" +SIGN_ROOT + "/" +  CardSign.getProfileContent().image_signature_name +".jpg?"+Math.random()+"  style='width:148px;height:106px;margin: 0px 4px 20px 15px; float: left; display: inline;'/>" 
							+"<div id='textCardSign' style='margin: 0px 28px 28px 0px; float: left;'>" +decideSignature() +"</div>"
							+"<div style='clear:both;'></div>"
							+"</div>";
						}else {
							Editor.c().document.getElementById(ID_SIGN).innerHTML = "<br/><div id='imageSign' style='height:150px'>"
							+"<img src='" + MailConst.IMG + "/demo1.jpg' style='width:148px;height:106px;margin: 0px 4px 20px 15px; float: left; display: inline;'/>" 
							+"<div id='textCardSign' style='margin: 0px 28px 28px 0px; float: left;'>" +decideSignature() +"</div>"
							+"<div style='clear:both;'></div>"
							+"</div>";
						}
				}
			} catch(e) {}
		} else if(Editor.c().document.getElementById('sohu_mail_stationery_content')){
			Editor.c().document.getElementById('sohu_mail_stationery_content').innerHTML += currentSign;
		}
		else{

			var _mc = Editor.c().document.getElementById("mailcontent");
            if (_mc) {
            	try {
            		var _txt = _mc.innerHTML;
            		_mc.innerHTML = currentSign + '<div>' + _txt + '</div>';
            	} catch(e) {
            		alert(e.description);
            	}
				
			}
			else {
				writemail.setContentInput(writemail.getContentInput() + currentSign);
			}
		}
	}
	
function addCommonSignInWriteMail() {
	if (!CardSign.getProfileContent().signatureCommon|| CardSign.getProfileContent().signatureCommon.strip() == "{}") {
		alert("您的普通签名为空，请先设置签名！");
		return;
	}
	if (writemail.defaulteditor == "html") {
		try {
			if(!CardSign.getProfileContent().image_signature) {
				var currentSign = "<div id='"+ID_SIGN+"'><br/><br/><div id='textCommonSign'>"
				+CardSign.getProfileContent().signatureCommon+ "</div></div>";
			} else {
				if (CardSign.getProfileContent().image_signature_name) {
					var currentSign = "<div id='"+ID_SIGN+"'><br/><br/> <div id='imageSign' style='height:150px'><img src="+SIGN_ROOT + "/" + CardSign.getProfileContent().image_signature_name +".jpg?"+Math.random()+ "  style='width:148px;height:106px;margin: 0px 4px 8px 15px; float: left; display: inline;'/>"
					+"<div id='textCommonSign'  style='margin: 0px 28px 28px 12px; float: left;color:#4c4c4c;'>" +CardSign.getProfileContent().signatureCommon
					+"</div></div><div style='clear:both;'></div></div>";
				}else{
					var currentSign = "<div id='"+ID_SIGN+"'><br/><br/> <div id='imageSign' style='height:150px'><img src='"+ MailConst.IMG+"/demo1.jpg'  style='width:148px;height:106px;margin: 0px 4px 20px 15px; float: left; display: inline;'/>" 
					+"<div id='textCommonSign' style='margin: 0px 28px 28px 12px; float: left;color:#4c4c4c;'>"+CardSign.getProfileContent().signatureCommon+
					"</div></div><div style='clear:both;'></div></div>";
				}
			}
		} catch(e) {}
	} else {
		var currentSign = "\n\n\n\n\n \n "+ CardSign.getProfileContent().signatureCommon;
	}
	if (Editor.c().document.getElementById(ID_SIGN)&& Editor.c().document.getElementById(ID_SIGN) != null) {

		try {
			if(!CardSign.getProfileContent().image_signature) {
				Editor.c().document.getElementById(ID_SIGN).innerHTML = "<br/> <br/><div id='textCommonSign'>" +
					CardSign.getProfileContent().signatureCommon+"</div>";
			} else {
				if (CardSign.getProfileContent().image_signature_name) {
						Editor.c().document.getElementById(ID_SIGN).innerHTML = "<br/> <div id='imageSign' style='height:150px'><img src=" +SIGN_ROOT + "/" +  CardSign.getProfileContent().image_signature_name +".jpg?"+Math.random()+ "  style='width:148px;height:106px;margin: 0px 4px 20px 15px; float: left; display: inline;'/>" +
						"<div id='textCommonSign' style='margin: 0px 28px 28px 12px; float: left;color:#4c4c4c;'>" +
						CardSign.getProfileContent().signatureCommon +
						"</div><div style='clear:both;'></div></div>";
					}else {
						Editor.c().document.getElementById(ID_SIGN).innerHTML = "<br/><div id='imageSign' style='height:150px'><img src='" + MailConst.IMG + "/demo1.jpg' style='width:148px;height:106px;margin: 0px 4px 20px 15px; float: left; display: inline;'/>" +
						"<div id='textCommonSign' style='margin: 0px 28px 28px 12px; float: left;color:#4c4c4c;'>" +
						CardSign.getProfileContent().signatureCommon+
						"</div><div style='clear:both;'></div></div>";
					}
			}
		} catch(e) {}
	} else {
		var _mc = Editor.c().document.getElementById("mailcontent");
		if (_mc) {
			try {
				var _txt = _mc.innerHTML;
				_mc.innerHTML = currentSign + '<div>' + _txt + '</div>';
			} catch(e) {
				alert(e.description);
			}
			
		}
		else {
			writemail.setContentInput(writemail.getContentInput() + currentSign);
		}
	}
}
function decideSignature() {
		var tmplate ='<div id="wordsign" style="font-family:Arial,Helvetica,sans-serif;font-size:12px;margin-left:10px;color:#4c4c4c;line-height:1.6em;">'
							   +'<font style="font-weight:bold;font-size:14px;"> #{username} #{userdepartment}</font>'
							   +'#{usercompany}'
							   +'#{userwebpage}'
							   +'#{userbusiness_address}'
							   +'#{userpostalcode}'
							   +'#{userphone}'
							   +'#{usermobile}'
							   +'#{useremail}'
							   +'#{userfax}'
							   +'#{usermsn}'
							   +'#{userqq}'
							+'</div>';
		var t = new Template(tmplate);	
		var data = new Object();
		if(CardSign.get_profile_content.signatureCard){
			var tmpsign=CardSign.getProfileContent().signatureCard.evalJSON();
			if (tmpsign.userdepartment == "") {
				tmpsign.username == "" ? data['username'] = "" : data['username'] = tmpsign.username+"<br/>";
			}else{
				tmpsign.username == "" ? data['username'] = "" : data['username'] = tmpsign.username;
			}
			tmpsign.userdepartment==""?data['userdepartment']="":data['userdepartment']=tmpsign.userdepartment+"<br/>";
			tmpsign.usercompany==""?data['usercompany']="":data['usercompany']="公&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;司 : "+tmpsign.usercompany+"<br/>";
			tmpsign.userwebpage==""?data['userwebpage']="":data['userwebpage']="网&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;址 : "+tmpsign.userwebpage+"<br/>";
			tmpsign.userbusiness_address==""?data['userbusiness_address']="":data['userbusiness_address']="办公地址 : "+tmpsign.userbusiness_address+"<br/>";
			tmpsign.userpostalcode==""?data['userpostalcode']="":data['userpostalcode']="邮政编码 : "+tmpsign.userpostalcode+"<br/>";
			tmpsign.userphone==""?data['userphone']="":data['userphone']="电&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;话 : "+tmpsign.userphone+"<br/>";
			tmpsign.usermobile==""?data['usermobile']="":data['usermobile']="手&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;机 : "+tmpsign.usermobile+"<br/>";
			tmpsign.useremail==""?data['useremail']="":data['useremail']="电子邮件 : "+tmpsign.useremail+"<br/>";
			tmpsign.userfax==""?data['userfax']="":data['userfax']="传&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;真 : "+tmpsign.userfax+"<br/>";
			tmpsign.usermsn==""?data['usermsn']="":data['usermsn']="MSN : "+tmpsign.usermsn+"<br/>";
			tmpsign.userqq==""?data['userqq']="":data['userqq']="QQ : "+tmpsign.userqq+"<br/>";
		}else{
			data['username']="";
			data['userdepartment']="";
			data['usercompany']="";
			data['userwebpage']="";
			data['userbusiness_address']="";
			data['userpostalcode']="";
			data['userphone']="";
			data['usermobile']="";
			data['userfax']="";
			data['useremail']="";
			data['usermsn']="";
			data['userqq']="";
		}
		return t.evaluate(data);
}
//打开续费链接
function openLinkForPay() {
	var action = "http://vip.sohu.com/confirmPassportSuccessAction.action?email="+UID;
	window.open(action);
}
/************发件人数量的过滤器，如果返会false将不会发送邮件***********/
function receiverFilterBeforeSendMail(p){
	var num = 0;
	for (var key in p){
		if (p[key] instanceof Array)
			num += p[key].length;
	}
	if(num > G.maxReceiverNum){
		var info="您的邮箱处于"+G.mailStatus+"期,";
		switch(parseInt(G.userinfo.user_ext_status)){
			case 0 :
			case 2 :
			case 3 :{
				info += "最多可群发"+G.maxReceiverNum+"人<br/>"
				+"续费后，群发数量可增至"+G.maxReceiverNumNormal+"人";
				break;
			}
			case 1 :{
				info += "已开启了批量群发功能<br/><br/>"
						+ "群发数量最多"+G.maxReceiverNumNormal+"人";
				break;
			}
			case 4 :
			case 6 :{
				info += "不能外发邮件<br/>"
						+ "续费后，群发数量可达"+G.maxReceiverNumNormal+"人";
				break;
			}
		}//end switch
		_dialog.alert({info:info});
		return false;		 
	 }// end if
	 return true;
}

function checkSignBeforeSendMail(){
	var ele_sign = Editor.c().document.getElementById(ID_SIGN);
	if(ele_sign){
		ele_sign.id += "_tmp";
	}
	return true;
}
//发件前的过滤器
function filterBeforeSendMail(p){
	var ret = receiverFilterBeforeSendMail(p);
	if(!ret)
		return false;
	ret = checkSignBeforeSendMail();
	return ret;
}
//pop收信过滤器
function pop3MailFilter(p){
	
	switch (p){
		case "getPop3List":{
			if(G.isTryoutFrozen)
				$("ID_POP_ALERT_MSG").innerHTML = "您的邮箱处于试用-冻结期，请续费后使用此功能。若未及时续费，邮箱到期后将被删除。";			
			break;
		}
		case "setPop3Account":{
			break;
		}
		case "getPopMail":{
			break;
		}
		case "alterPop3Info":{
			break;
		}	
	}//end switch;
	return !frozenAlert();
}
//udisk filter: return true if this user has udisk rights
function udiskRightsFilter(){
	return !frozenAlert(true);
}

///冻结期提醒
function frozenAlert(flag){
	if( (!G.isTryoutFrozen && !G.isFrozen) || (G.isFrozen && !flag) ){
		return false;
	}	
	var Temp = new Template(frozenAlertTemplate);
	var data = new Object();
	data["EMAILSTATUS"] = G.mailStatus;
	var html = "<div style='padding:5px'>"
			 + Temp.evaluate(data) 
			 + "<div style='text-align:center;margin:10px 5px 5px 5px'>"
			 + "<button onclick='openLinkForPay();customDialog.close()'>确定</button>"
			 + "<button onclick='customDialog.close()' style='margin-left:20px;'>取消</button>&nbsp;&nbsp;"
			 + "</div>"
			 + "</div>";
	var info = {
			title:"邮箱"+data["EMAILSTATUS"]+"期提醒",
			html:html,
			style:"width:300px;height:250px;"
		};	
	//setTimeout(function(){customDialog.custom(info)},3000);
	customDialog.custom(info);
	return true;
}
//切换在线翻译的状态
function shiftTranslate(){
	if(frozenAlert()){
		K.config.enabled = false;
		return;
	}
	K.start();
	shiftTranslate.setStatus();
	return K.config.enabled;	
}

shiftTranslate.addMangeEle = function(p){
	if(!p || typeof(p)!="object")
		return;
	if(!shiftTranslate.data)
		shiftTranslate.data = {};
	if(p.key&&p.ele){
		shiftTranslate.data[p.key]= p.ele;
	}
	shiftTranslate.setStatus();
}
shiftTranslate.setStatus = function(){
	var title="在线翻译"+(ExecFunc("K.config.enabled",null,false)?"[已打开]":"[已关闭]");
	if(shiftTranslate.data && typeof(shiftTranslate.data)=="object"){
		for (key in shiftTranslate.data){
			shiftTranslate.data[key].title=title;
		}
	}
}

//为Dialog增加接口 ......
Dialog.prototype.openMapWin = function(){
		
		var paramers=arguments[0]
		var dlg = this.createDialog();
		//quzhi 添加
		this.drag=this.creatDrag();
		//
		/*
		Element.setStyle(dlg,{padding:'0px 0px 0px 0px',border:'3px solid #599BC9'});
		Element.setStyle(dlg.firstChild,{background: '#EDF5F7 none repeat scroll 0 0'});
		Element.setStyle(dlg.firstChild.firstChild,{padding:'0 0 0 0',fontSize:'12px'});
		Element.setStyle(this.content,{height:'273px'});
		*/
		dlg.firstChild.firstChild.innerHTML = paramers.title;
		$('mProvince').options.length = mapProvince.length;
		for (var i = 0; i < mapProvince.length; i++) { 
			$('mProvince').options[i].text = $('mProvince').options[i].value =mapProvince[i]; 
		}
		//根据用户登陆IP，显示用户省份
		if(IP!=""&&IP.split('|').length==2){
			$('mProvince').value=IP.split('|')[0];
		}
		//添加下方显示条
		if(!$('bottomMapbar')){
			var div = document.createElement("div");
			div.innerHTML = paramers.html;
			dlg.appendChild(div);

		}		
		Element.setStyle(this.createDialog(), paramers.style);
		Element.setStyle(this.dialog.getElementsByTagName('iframe')[0], paramers.style);
		// 加载地图
		this.content.innerHTML = '<iframe id="smap" src="'+MailConst.CONTEXT+'/control.html"  frameborder="0" scrolling="no" width="420" height="273" style="margin-top:1px"></iframe>';
		
		this.showLayer();
		Element.show(this.dialog);
		var self = this;
		Event.observe($(dlg).getElementsByClassName("s_map_dialog_close")[0],"click",function(evt){self.close();});
		Event.observe($(dlg).getElementsByClassName("s_map_save")[0],"click",function(evt){saveMap();});
		Event.observe($(dlg).getElementsByClassName("s_map_search")[0],"click",function(evt){searchMap();});
	}
Dialog.prototype.creatDrag = function(){
		var myDrag=new Draggable($(this.dialog), {
            // scroll:$('main_body_box'),
            snap: function(x, y, draggable) {
                function constrain(n, lower, upper){
                    if (n > upper) 
                        return upper;
                    else 
                        if (n < lower) 
                            return lower;
                        else 
                            return n;
                }
                var element_dimensions = Element.getDimensions(draggable.element);
                var parent_dimensions = Element.getDimensions(draggable.element.previousSibling);
                return [constrain(x, 0, (parent_dimensions.width - 12) - element_dimensions.width), constrain(y, 0, (parent_dimensions.height - 22) - element_dimensions.height)];
            },
            handle: this.dialog.firstChild.firstChild,
			zindex: 10001,
            starteffect: false,
            endeffect: false
        });
		return myDrag;
	}

Dialog.prototype.ding = function(){
		var tmpString=$('fix').src.substring($('fix').src.lastIndexOf('/')+1);
		//console.log(tmpString);
		if(tmpString=='dw.gif'){
			$('fix').src=MailConst.ALL+"/dw2.gif";
			this.drag.destroy();	
			//console.log(this.drag);
		}else{
			$('fix').src=MailConst.ALL+"/dw.gif";
			this.drag=this.creatDrag();
			//console.log(this.drag);
		}
		
	}

//检索地图
function searchMap(){
	function encode(a){
		var b=escape(a);
		return b.replace(/%u/g,"%25u")
	}
	var geoEngine="http://lspengine4.go2map.com/geocoder/engine";
	var c=geoEngine+"?city="+encode($('mProvince').options[$('mProvince').selectedIndex].value)+"&addr="+encode($F("mapKey"))+"&cb=geoCallBack";
	$('smap').contentWindow.flush(c);
}
function saveMap(){
	$('smap').contentWindow.submitSaveMap();
}

function hrefSend(a){
	var location=$F("mapKey")?$F("mapKey"):$('mProvince').options[$('mProvince').selectedIndex].value;

	var add_mail_sign = Editor.c().document.getElementById(ID_SIGN);
	var u_Disk=Editor.c().document.getElementById("UDiskPanel");
	var map=Editor.c().document.getElementById("map");
	var link = "<div>"+ location+'：<a href="'+a+'" target="_blank">'+a+'</a>'+ "</div>";
	if(!map){
		map = Editor.c().document.createElement("div");
		map.id = "map";
		map.innerHTML = "<p><br/><br/><br/>----(下面的链接是您的朋友通过sogou地图给你的共享链接，你可以点击查看)<br/></p>";
		if(add_mail_sign){
			Editor.c().document.body.insertBefore(map,add_mail_sign);
		}
		else{
			try{
			Editor.c().document.body.appendChild(map);
			}
			catch(e){alert(e)}
		}
	}
	map.innerHTML += link;
	
	customDialog.close();
	return;

	var html;
	if(!(map&&map!=null)){
		html='<br /><br /><br /><div id="map">'
			+'<div>'
			+'----(下面的链接是您的朋友通过sogou地图给你的共享链接，你可以点击查看)<br/>'
			+location+'：<a href="'+a+'" target="_blank">'+a+'</a>'
			+'</div>'
			+'</div>';
	}else{
		html=location+'：<a href="'+a+'" target="_blank">'+a+'</a>'
	}
	//判断签名的div是否存在
	if(add_mail_sign&& add_mail_sign != null){
		//判断Editor里面是否存在map的Div
		if(!(map&&map!=null)){
			Editor.setContent(html+Editor.getContent());
		}else{
			var _div=Editor.c().document.createElement('div');
			_div.innerHTML=html;
			map.appendChild(_div)
		}
	}
	//判断U盘的div是否存在
	else if(u_Disk&&u_Disk!=null){
		//判断Editor里面是否存在map的Div
		if(!(map&&map!=null)){
			Editor.setContent(html+Editor.getContent());
		}else{
			var _div=Editor.c().document.createElement('div');
			_div.innerHTML=html;
			map.appendChild(_div)
		}
	}else{
		//判断Editor里面是否存在map的Div
		if(!(map&&map!=null)){
			Editor.setContent(html);
		}else{
			var _div=Editor.c().document.createElement('div');
			_div.innerHTML=html;
			map.appendChild(_div);
		}
	}	
}

///////////////////////////////
// 显示发件人数量提示
var isShowReceiverNum = false;
function receiverNumPrompt() {
	if(isShowReceiverNum || G.isNormal)return;
	var div= document.createElement('div');
	var imgUrl = MailConst.ALL+"/tip"+(parseInt(G.userinfo.user_email_type)+1)+".gif";
	with(div.style) {
		if (Prototype.Browser.IE) {
			filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' +imgUrl+ '\')';
		} else {
			background = 'url(' + imgUrl+ ') no-repeat';
		}
		position   = 'absolute';
		zIndex     = '888';
		left       = '480px';
		top        = '60px';
		width      = '108px';
		height     = '78px';
	};
	var _close = document.createElement('span');
	with(_close.style) {
		border          = '1px solid #BBBBBB';
		backgroundColor = '#EFEFEF';
		position        = 'absolute';
		left       = '565px';
		top        = '70px';
		zIndex          = '999';
		color           = '#888888';
		fontSize        = '10px';
		width  = height = '9px';
		lineHeight      = '3px';
		cursor          = 'pointer';
		display         = 'block';
		
	};
	_close.onmouseover = function() {
		with(this.style) {
			borderColor     = '#666666';
			backgroundColor = '#FFFFFF';
			color           = '#333333';
		};
	};
	_close.onmouseout = function() {
		with(this.style) {
			borderColor     = '#BBBBBB';
			backgroundColor = '#EFEFEF';
			color           = '#888888';
		};
	};
	var close_func = function() {
		try {
			div.parentNode.removeChild(div);
			_close.parentNode.removeChild(_close);
			div = null;
			_close = null;
		} catch(e) {}
		try {
			_close.onmouseover = null;
			_close.onmouseout = null;
			_close.onclick = null;
			_close = null;
		} catch(e) {}
	};
	_close.onclick = function(){
		close_func();
	};
	
	_close.innerHTML = '<div style="margin:2px;">x</div>';
	document.body.appendChild(div);
	document.body.appendChild(_close);
	var __t = setTimeout(function() {
		clearTimeout(__t);
		__t = null;
		close_func();
	}, 8000);
	isShowReceiverNum=true;
}

//
// 杀毒多封邮件
function clickantivirus() {
	GetSMails = (isConferenceMode?mailConference:mailList).getSelectMailList().selected;
	if (GetSMails == '' || GetSMails == null) {
		alert('请选择您要操作的邮件');
		return;
	}
	var count = GetSMails.length;
	var id = GetSMails.pop();
	/*
	_currentPageFolderList.each(function(mailItem) {
		mailItem.checked = false;
		$('tr_' + mailItem.id).style.backgroundColor = '';
	});
	$('formNode').getElementsBySelector('input').each(function(_element) {
		_element.checked = false;
	});*/
	window.open("./killvirus?id="+id+"&count="+count,"antispam","width=450,height=380,scrollbars=no,resizable=no");	
}

////////////创建杀毒按钮//////////////
function createBtnInMailList(){
	return [ createAntiVirusBtn() ];
}
function createAntiVirusBtn(){
		var span = document.createElement('li');
		Element.setStyle(span,{"float":"left"});
		span.onclick=function(){clickantivirus();};
		span.innerHTML = '<span class="s_antivirus" hidefocus="true"><img src="'+ MailConst.ALL +'/spacer.gif" class="am icon-antivirus" align="absmiddle" style="margin-top:7px"/></span>';
		return span;
}
function createBtnInReadMail(){
	if(!G.hasTranslateRights())
		return null;
	return [createTanslateOnLineBtn()];
}
function createTanslateOnLineBtn(){
		var li = document.createElement('li');
		li.style.cursor="pointer";
		li.onclick=function(){shiftTranslate();};
		li.title="在线翻译"+(K.config.enabled?"[已打开]":"[已关闭]");

		li.innerHTML = '<a class="button s_ciba" hidefocus="true"><em><img src="'+ MailConst.ALL +'/spacer.gif" width="20px" height="20px" class="am editor-ciba" align="absmiddle"/></em>在线翻译</a>';
		shiftTranslate.addMangeEle({key:"s_ciba",ele:li});
		return li;
}

function getMobileTemplate(){
	if (G.userinfo.user_email_type==0){
		return mobileMailCfgTemplate_vip220;
	}
	return mobileMailCfgTemplate;
}

function payForMail() {
	var action = "http://vip.sohu.com/confirmPassportSuccessAction.action?email="+UID;
	window.open(action);
}
//写信前过滤器
function filterBeforeWriteMail(p){
	frozenAlert(p);
}

function initCiba(){
	ExecFunc("K.config.inited=false");
	_iframes = document.getElementsByTagName('iframe');	
	try{
		j=0;
		for(i=0;i<_iframes.length;i++){ 
			ifr=_iframes[i];
			if( ifr.src.indexOf('http://')<0 || ifr.src.indexOf('http://'+window.location.host)==0 ){
			     K.iframes[j]=ifr;	
				 j++;
			}
	
		}
		for(i=0;i<K.iframes.length;i++){
		  ifr=K.iframes[i];			  
		  K.observe(ifr.contentWindow.document,'mousedown',K.Close);
		  K.observe(ifr.contentWindow.document,'mouseup',K.Query);	
		}
	}
	catch(e){
	}
};